-
Notifications
You must be signed in to change notification settings - Fork 739
Set RuntimeIdentifier when building dotnet containers #12936
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Set both RuntimeIdentifier/ContainerRuntimeIdentifier or RuntimeIdentifiers/ContainerRuntimeIdentifiers when building dotnet containers. This way the application is published correctly - for example for native AOT.
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 12936Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 12936" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR enhances container image building for .NET projects by setting both RuntimeIdentifier/RuntimeIdentifiers and ContainerRuntimeIdentifier/ContainerRuntimeIdentifiers MSBuild properties when building dotnet containers. This ensures applications are published correctly for scenarios like Native AOT compilation. Additionally, the PR removes the ContainerRegistry property from several playground TestShop project files.
Key changes:
- Sets
RuntimeIdentifieralongsideContainerRuntimeIdentifierfor single-platform builds - Sets
RuntimeIdentifiersalongsideContainerRuntimeIdentifiersfor multi-platform builds - Removes unused
ContainerRegistryproperty from three TestShop playground projects
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/Aspire.Hosting/Publishing/ResourceContainerImageBuilder.cs | Adds RuntimeIdentifier/RuntimeIdentifiers properties to dotnet publish command for both single and multi-platform builds |
| playground/TestShop/MyFrontend/MyFrontend.csproj | Removes ContainerRegistry property from project file |
| playground/TestShop/CatalogService/CatalogService.csproj | Removes ContainerRegistry property from project file |
| playground/TestShop/BasketService/BasketService.csproj | Removes ContainerRegistry property from project file |
| { | ||
| // Single platform - use ContainerRuntimeIdentifier | ||
| // Single platform - use RuntimeIdentifier/ContainerRuntimeIdentifier | ||
| arguments += $" /p:RuntimeIdentifier=\"{ridArray[0]}\""; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: What was the failure mode here? From what I recall, we always just set ContainerRuntimeIdentifier since this was introduced in 9.4. Was this breaking AoT in some way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When you aspire do build a project like this:
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<PublishTrimmed>true</PublishTrimmed>
<PublishSelfContained>true</PublishSelfContained>
<PublishReadyToRun>true</PublishReadyToRun>
</PropertyGroup>from a Windows machine, it is going dotnet publish that project on the current machine (Windows) and put it in a Linux docker image. So you end up with Windows exectuables and .dlls in the image, and obviously the image doesn't run correctly. Specifying both RuntimeIdentifier and ContainerRuntimeIdentifier fixes this because the app is published for linux-x64 and put in a linux-x64 image.
For PublishAot=true, we don't expect this scenario to actually work end-to-end. But at least now you get an error saying (when you use --log-level debug):
Microsoft.NETCore.Native.Publish.targets(60,5): error : Cross-OS native compilation is not
supported. [D:\DotNetTest\nettest\nettest.ApiService\nettest.ApiService.csproj]
captainsafia
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quote escaping works for me on macOS although this is still just passing a single RID.
Description
Set both RuntimeIdentifier/ContainerRuntimeIdentifier or RuntimeIdentifiers/ContainerRuntimeIdentifiers when building dotnet containers. This way the application is published correctly - for example for native AOT.